package com.xingqing.service.impl;

import com.xingqing.domain.entity.WorkExperience;
import com.xingqing.repository.WorkExperienceMapper;
import com.xingqing.service.WorkExperienceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class WorkExperienceServiceImpl implements WorkExperienceService {

    @Autowired
    private WorkExperienceMapper workExperienceMapper;

    @Override
    public List<WorkExperience> list() {
        return workExperienceMapper.selectAll();
    }

    @Override
    public WorkExperience getById(Long id) {
        return workExperienceMapper.selectById(id);
    }

    @Override
    public List<WorkExperience> getByEmpId(Long empId) {
        return workExperienceMapper.selectByEmpId(empId);
    }

    @Override
    public void save(WorkExperience workExperience) {
        workExperience.setCreateTime(LocalDateTime.now());
        workExperience.setUpdateTime(LocalDateTime.now());
        workExperienceMapper.insert(workExperience);
    }

    @Override
    public void saveBatch(List<WorkExperience> workExperiences) {
        if (workExperiences == null || workExperiences.isEmpty()) {
            return;
        }
        
        LocalDateTime now = LocalDateTime.now();
        for (WorkExperience workExperience : workExperiences) {
            workExperience.setCreateTime(now);
            workExperience.setUpdateTime(now);
        }
        
        log.info("批量新增{}条工作经历", workExperiences.size());
        workExperienceMapper.insertBatch(workExperiences);
    }

    @Override
    public void updateById(WorkExperience workExperience) {
        workExperience.setUpdateTime(LocalDateTime.now());
        workExperienceMapper.updateById(workExperience);
    }

    @Override
    public void deleteById(Long id) {
        workExperienceMapper.deleteById(id);
    }

    @Override
    public void deleteByEmpId(Long empId) {
        log.info("删除员工所有工作经历，员工ID: {}", empId);
        workExperienceMapper.deleteByEmpId(empId);
    }
}